package scm.erp.sale.order.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.poi.hpsf.Decimal;
import scm.erp.core.domain.CommonFields;
import scm.erp.core.domain.IConvert;
import scm.erp.core.mybatis.interceptor.annotation.UUID;
import scm.erp.sale.order.enums.OrderStatus;
import scm.erp.sale.plan.domain.Plan;
import scm.erp.sale.refund.enums.RefundStatus;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
public class Order {
    public static class Entity
            extends CommonFields
            implements IConvert {
        @UUID
        private String id;
        private String orderCode;
        private String planCode;
        private String site;
        private String customerName;
        private Float number;
        private BigDecimal amount = BigDecimal.ZERO;
        private String carNumber;
        private String trailerNumber;
        private String driverName;
        private Integer phone;
        private String freightName;
        private String freightCode;
        private BigDecimal freightPrice = BigDecimal.ZERO;
        private String remark;
        private OrderStatus orderStatus;
        private RefundStatus refundStatus;
        public OrderStatus getOrderStatus(){
            if (orderStatus==null){
                return OrderStatus.DEFAULT;
            }
            return orderStatus;
        }
        public RefundStatus getRefundStatus(){
            if (refundStatus==null){
                return RefundStatus.APPLY;
            }
            return refundStatus;
        }
    }
    /**
     * 实体继承
     */
    @EqualsAndHashCode(callSuper = true)
    @Data
    public static class Vo extends Plan.Entity {

    }
    /**
     * 订单状态批量更新请求参数类
     */
    @Data
    public static class OrderStatusUpdateRequest {

        /**
         * 目标状态（枚举类型，不能为空）
         */
        @NotNull(message = "目标状态不能为空")
        private OrderStatus orderStatus = OrderStatus.DEFAULT; // 初始化默认值，替代冗余的空值判断

        /**
         * 待更新的订单ID列表（至少1个ID，不能为空）
         */
        @NotEmpty(message = "订单ID列表不能为空")
        private List<String> ids;

        // 移除冗余的getOrderStatus方法，通过Lombok @Data自动生成getter，且字段初始化保证非空
    }
    /**
     * 搜索
     */
    @Data
    public static class searchOrderCodeVo{
        private String orderCode;
    }
    @Data
    public static class searchSiteVo{
        private String site;
    }
    @Data
    public static class searchCreatTimeVo{
        private LocalDateTime creatTime;
    }
    @Data
    public static class searchFreightName{
        private String freightName;
    }
    /**
     * 查询
     */
    @Data
    public static class SearchVo {
        private String id;
        private String orderCode;
        private String site;
        private String customerName;
        private String carNumber;
        private Integer freightName;
        private OrderStatus orderStatus;
        private RefundStatus refundStatus;
        private Integer deleteFlag;
    }
    @Data
    public static class ExcelExportVo implements IConvert{
        @ExcelProperty("订单编码")
        private String orderCode;
        @ExcelProperty("客户名称")
        private String customerName;
        @ExcelProperty("货物名称")
        private String freightName;
        @ExcelProperty("货物编码")
        private String freightCode;
        @ExcelProperty("单价")
        private String freightPrice;
        @ExcelProperty("数量")
        private String number;
        @ExcelProperty("金额")
        private String amount;
        @ExcelProperty("站点")
        private String site;
        @ExcelProperty("订单状态")
        private String orderStatusName;
        @ExcelProperty("退款状态")
        private String refundStatus;
        @ExcelProperty("车牌号")
        private String carNumber;
        @ExcelProperty("挂牌号")
        private String trailerNumber;
        @ExcelProperty("联系电话")
        private String phone;
        @ExcelProperty("备注")
        private String remark;
        @ExcelProperty("创建人")
        private String createUser;
        @ExcelProperty("创建时间")
        private LocalDateTime createTime;
        @ExcelIgnore
        private OrderStatus orderStatus;
        public String getName(){
            if (orderStatus!=null){
                return orderStatus.getName();
            }
            return orderStatusName;
        }
    }
}
